<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order extends MX_Controller {


	function __construct(){
	
		//$this->load->library('auth/tank_auth');
		if (!Modules::run('auth/is_login'))
			redirect('/auth/login/manager');

		$this->load->model('order_model');
		$this->load->library('pagination');		

	}
	
	function orders(){
		$user_id = Modules::run('auth/get_user_id');
		
		$store = $this->order_model->get_store($user_id);
		
		if ($store == NULL){
			$this->load->view('empty_store');	
		}else{
		
			$offset = $this->uri->segment(3);
			$limit = '10';
			if(!$offset){
				$page = 0;
			}else{
				$page = $offset; 	
			}
			
			$data['order'] = $this->order_model->get_order_by_store($store->toko_id, $page, $limit);
			
			$config_pagination['base_url']    = site_url('order/orders');
			$config_pagination['total_rows']  = count( $this->order_model->get_order_by_store($store->toko_id,'0','0'));
			$config_pagination['per_page']    = $limit;
			$config_pagination['uri_segment'] = 3;
			$config_pagination['num_links']   = 4;
	
			//pagination style
			$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
			$config_pagination['full_tag_close'] = '</ul></div>';
	
			$config_pagination['first_link'] = 'First';
			$config_pagination['first_tag_open']  = '<li>';
			$config_pagination['first_tag_close'] = '</li>';
	
			$config_pagination['last_link'] = 'Last';
			$config_pagination['last_tag_open']  = '<li>';
			$config_pagination['last_tag_close'] = '</li>';
	
			$config_pagination['next_link'] = '&gt;';
			$config_pagination['next_tag_open']  = '<li>';
			$config_pagination['next_tag_close'] = '</li>';
	
			$config_pagination['prev_link'] = '&lt;';
			$config_pagination['prev_tag_open'] = '<li>';
			$config_pagination['prev_tag_close'] = '</li>';
	
			$config_pagination['cur_tag_open'] = '<li class="disabled"><a href="#">';
			$config_pagination['cur_tag_close'] = '</a></li>';
	
			$config_pagination['num_tag_open'] = '<li>';
			$config_pagination['num_tag_close'] = '</li>';
	
			$this->pagination->initialize($config_pagination); 
	
			$data['pagination'] = $this->pagination->create_links();
			
			$this->load->view('order', $data);
		}
	}

	function info($order_id){

		$user_id = Modules::run('auth/get_user_id');
		
		$data['order'] = $this->order_model->get_order_by_id($order_id);
		
		$this->load->view('order_info', $data);
	}

	/*function update($order_id){
		$user_id = Modules::run('auth/get_user_id');
		
		if($_POST == NULL){
			$data['order'] = $this->order_model->get_order_by_id($order_id);
			$this->load->view('order_form_update', $data);
		}else{
			$this->order_model->update($order_id, $_POST);
			redirect('order/orders');
		}
		
	}*/
	
	function status($order_id){
		$user_id = Modules::run('auth/get_user_id');
		if($_POST == NULL){
			$data['order'] = $this->order_model->get_order_by_id($order_id);
			$this->load->view('order_info', $data);
		}else{
			$this->order_model->add_history($order_id);
			$this->order_model->update_status($order_id, $_POST);
			redirect('order/info/'.$order_id);
		}
	}
	
	/*function history(){
		$user_id = Modules::run('auth/get_user_id');
		
		$customer = $this->order_model->get_customer_by_user($user_id);
		
		$offset = $this->uri->segment(3);
		$limit = '10';
		if(!$offset){
			$page = 0;
		}else{
			$page = $offset; 	
		}
		
		$data['order'] = $this->order_model->get_order_by_customer($customer->customer_id);
		
		$config_pagination['base_url']    = site_url('order/history');
		$config_pagination['total_rows']  = count( $this->order_model->get_order_by_customer($customer->customer_id,'0','0'));
		$config_pagination['per_page']    = $limit;
		$config_pagination['uri_segment'] = 3;
		$config_pagination['num_links']   = 4;

		//pagination style
		$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
		$config_pagination['full_tag_close'] = '</ul></div>';

		$config_pagination['first_link'] = 'First';
		$config_pagination['first_tag_open']  = '<li>';
		$config_pagination['first_tag_close'] = '</li>';

		$config_pagination['last_link'] = 'Last';
		$config_pagination['last_tag_open']  = '<li>';
		$config_pagination['last_tag_close'] = '</li>';

		$config_pagination['next_link'] = '&gt;';
		$config_pagination['next_tag_open']  = '<li>';
		$config_pagination['next_tag_close'] = '</li>';

		$config_pagination['prev_link'] = '&lt;';
		$config_pagination['prev_tag_open'] = '<li>';
		$config_pagination['prev_tag_close'] = '</li>';

		$config_pagination['cur_tag_open'] = '<li class="disabled"><a href="#">';
		$config_pagination['cur_tag_close'] = '</a></li>';

		$config_pagination['num_tag_open'] = '<li>';
		$config_pagination['num_tag_close'] = '</li>';

		$this->pagination->initialize($config_pagination); 

		$data['pagination'] = $this->pagination->create_links();
		
		$this->load->view('order_history', $data);
	}
	
	function history_info($order_cid = ''){
		$user_id = Modules::run('auth/get_user_id');
		
		$data['order'] = $this->order_model->get_order_by_cid($order_cid);
		
		$this->load->view('order_history_info', $data);
	}*/
	
	/*function get_history($order_id){
		$user_id = Modules::run('auth/get_user_id');
		
		$offset = $this->uri->segment(3);
		$limit = '10';
		if(!$offset){
			$page = 0;
		}else{
			$page = $offset; 	
		}
		
		$data['get_history'] = $this->order_model->get_history($order_id, $page, $limit);
		
		$config_pagination['base_url']    = site_url('order/get_history');
		$config_pagination['total_rows']  = count( $this->order_model->get_history($order_id,'0','0'));
		$config_pagination['per_page']    = $limit;
		$config_pagination['uri_segment'] = 3;
		$config_pagination['num_links']   = 4;

		//pagination style
		$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
		$config_pagination['full_tag_close'] = '</ul></div>';

		$config_pagination['first_link'] = 'First';
		$config_pagination['first_tag_open']  = '<li>';
		$config_pagination['first_tag_close'] = '</li>';

		$config_pagination['last_link'] = 'Last';
		$config_pagination['last_tag_open']  = '<li>';
		$config_pagination['last_tag_close'] = '</li>';

		$config_pagination['next_link'] = '&gt;';
		$config_pagination['next_tag_open']  = '<li>';
		$config_pagination['next_tag_close'] = '</li>';

		$config_pagination['prev_link'] = '&lt;';
		$config_pagination['prev_tag_open'] = '<li>';
		$config_pagination['prev_tag_close'] = '</li>';

		$config_pagination['cur_tag_open'] = '<li class="disabled"><a href="#">';
		$config_pagination['cur_tag_close'] = '</a></li>';

		$config_pagination['num_tag_open'] = '<li>';
		$config_pagination['num_tag_close'] = '</li>';

		$this->pagination->initialize($config_pagination); 

		$data['pagination'] = $this->pagination->create_links();
		
		$this->load->view('order_info', $data);
	}*/

}

/* End of file manager.php */
